package com.kgc.dubbo.controller;
import com.kgc.dubbo.service.LocalUserService;
import com.kgc.dubbo.vo.RespResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@Api(value = "用户操作的控制器")
@RestController
@RequestMapping("/api")
public class UserController {
    @Autowired
    private LocalUserService localUserService;
    @ApiOperation(value = "根据电话号码、密码进行统一认证",
            httpMethod = "POST",notes = "根据用户名、密码进行统一认证",
            protocols = "http",produces = "application/json;charset=UTF-8",
            consumes = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "手机号",required = true,paramType = "form"),
            @ApiImplicitParam(name = "password",value = "密码",required = true,paramType = "form")
    })
    @PostMapping(value = "/doLogin")
    public RespResult doLogin(String phone,
                              String password,HttpServletResponse response) throws Exception {
        RespResult respResult = localUserService.login(phone,password);
        return respResult;
    }
    @ApiOperation(value = "退出功能",
            httpMethod = "POST",notes = "退出",
            protocols = "http",produces = "application/json;charset=UTF-8",
            consumes = "application.json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "token",required = true,paramType = "form")
    })
    @PostMapping(value = "/v/loginOut")
    public RespResult logout (String token) throws Exception {
        RespResult respResult = localUserService.logOut(token);
        return respResult;

    }

}
